﻿{include file="/public/header" /}
<div class="content-wraper full">
    <div class="tools-bar">
        <a data-key="add"><i class="fa fa-plus"></i> 添加</a>
        <a data-key="edit"><i class="fa fa-edit"></i> 编辑</a>
        <a data-key="lock"><i class="fa fa-lock"></i> 锁定</a>
        <a data-key="unlock"><i class="fa fa-unlock-alt"></i> 解锁</a>
        <a data-key="partner"><i class="fa fa-user-circle"></i> 合伙人</a>
    </div>

    <div class="normal-line"></div>
    <div class="search_wraper" style="min-height: 51px;">
        <form class="normal_form search_form" onsubmit="return false;">
            <div class="condition" onscroll="Core.scrolling(this)">
            </div>
            <div class="row form-footer-bar">
                <button class="btn" type="reset" role="btn-cancel">重置</button>
                <button r-button class="btn btn-primary search-btn" type="submit" role="btn-submit">搜索</button>
                <button r-button style="display: none;" class="btn switch_search filter">展开搜索条件<i class="fa fa-angle-down"></i></button>
                <div style="margin: 10px 0 -10px;"><a class="search_close"><i class="fa fa-angle-up"></i>收起</a></div>
            </div>
        </form>
    </div>
    <div class="table_box">
        <table class="table_main" id="datalist"></table>
    </div>
</div>
<script type="text/javascript">
Core.Easyui.FieldColumn = [
    {field:'parname',title:'合伙人[花名]',width:120,align:'center'},
    {field:'lnname',title:'联络人',width:120,align:'center'},
    {field:'lnphone',title:'联络手机',width:120,align:'center'},
    {field:'-link-',title:'门店管理',width:100,align:'center',formatter:function(value,row,index){
        return '<a onclick="javascript:Core.Sys.Action(\'klink\',this);" data-key="'+row.id+'" style="text-decoration:underline">点击管理</a>';
    }},
    {field:'setime',title:'服务起止时间',width:220,align:'center'},
    {field:'lng',title:'GPS经度',width:120,align:'center',formatter:function(value,row,index){
		return value || '';
	}},
    {field:'lat',title:'GPS纬度',width:120,align:'center',formatter:function(value,row,index){
		return value || '';
	}},
    {field:'juice',title:'起始特饮费(元)/小时价',width:150,align:'center'},
    {field:'trial',title:'起始免费时长(分钟)',width:120,align:'center'},
    {field:'capped',title:'封顶时长(分钟)',width:120,align:'center'},
    {field:'gtdmin',title:'起步时长',width:50,align:'center',formatter:function(value,row,index){
		return ['-','<i class="fa fa-check" style="color:green"></i>'][value] || '';
	}},
    {field:'state',title:'状态',width:50,align:'center',formatter:function(value,row,index){
		return ['-','<i class="fa fa-check" style="color:green"></i>','<span style="color:red">锁定</span>'][value] || '';
	}},
    {field:'region',title:'城市区域',width:180,align:'left'},
    {field:'address',title:'详细地址',width:220,align:'left'},
	{field:'sysmsg',title:'系统消息',align:'left'},
];
Core.Easyui.FrozenColumn = [
    {field:'ck',checkbox:true,width:30},
    {field:'id',title:'ID',width:50,align:'center'},
	{field:'title',title:'门店名称',width:250,align:'left', search: true, nowsearch: true, searchtype: 'input'},
];

Core.Easyui.init($("#datalist"), {
    url: "{$_G['_mc_'] ?? ''}/ajax",
    idField: "id",
    fitColumns: false,
    singleSelect : true,
    columns: [Core.Easyui.FieldColumn],
    frozenColumns: [Core.Easyui.FrozenColumn],
    pageSize: 50,
    onDblClickRow: function (index,row){
        Core.Sys.Action('pop',row);
    },
},$(".search_form"));


Core.Sys.Action = function(Tkey,row){
    switch(Tkey){
        case 'add':
            Core.Dialog.open({'title': '添加','width': '850px','height': '620px','url': "{$_G['_mc_'] ?? ''}/edit"});
        break;
        case 'edit':
            var row = $('#datalist').datagrid('getSelected');if (!row) return;
            Core.Sys.Action('pop',row);
        break;
        case 'pop':
            if (!row || !row.id) return;
            Core.Dialog.open({'title': '编辑','width': '850px','height': '620px','url': "{$_G['_mc_'] ?? ''}/edit/id/"+row.id});
        break;
        case 'lock':case 'unlock':
            var row = $('#datalist').datagrid('getSelected');if (!row) return;
            var Act = {
                'lock'   : {'n' : '锁定','txt' : '您确定要锁定该单位吗？锁定后将无法使用系统','v' : 2},
                'unlock' : {'n' : '解锁','txt' : '您确定要解锁该单位吗？解锁后将正常使用系统','v' : 1},
            };
            if (row.state == Act[Tkey].v) {
                Core.Dialog.msg('该单位已经'+Act[Tkey].n+'，无需再次操作');return;
            }


            Core.Dialog.confirm({'title': '提示信息','content': Act[Tkey].txt || '','ok': function (cbk) {
                    $.getJSON("/{$_G['_m_'] ?? ''}.channel/lock/p/"+Act[Tkey].v+"?id="+row.id+"&r="+Math.random(),function(data){
                        if(data.state != 'y'){
                            Core.Dialog.msg('操作失败，'+data.msg);
                        } else {
                            Core.Dialog.msg('操作成功');
                            $('#datalist').datagrid('reload');
                            cbk();
                        }                        
                    });
                },
            });
        break;
        case 'partner':
            var row = $('#datalist').datagrid('getSelected');if (!row) return;
            Core.Dialog.open({'title': '合伙人','width': '650px','height': '480px','url': "{$_G['_mc_'] ?? ''}/partner/id/"+row.id});
        break;
        case 'klink':
            let id = $(row).attr('data-key');
            if (!id || !Core.rule('intp',id)) {
                Core.Dialog.msg('请选择对应的门店进行操作');return;
            }
            $.getJSON("/{$_G['_m_'] ?? ''}.channel/klink?id="+id+"&r="+Math.random(),function(json){
                if(json.state != 'y'){
                    Core.Dialog.msg('操作失败，'+json.msg);
                } else {
                    window.top.location.href = json.data;
                }                        
            });
        break;
    }
    return;//unordertonet
}
$(document).ready(function(){
    $('.tools-bar').find('a[data-key]').on('click',function(){
        var Tkey = $(this).attr('data-key');
        if (!Core.rule('key',Tkey)) return false;
        Core.Sys.Action(Tkey);
    });
});

/**搜索 */
var Table_Filters = Core.Search.searchArray();
var filterType = Core.Search.typeList();
//var rsourceUrl = "/index/ajax/index"; //搜索字段基础数据
//var regionUrl = "/index/ajax/district/level/"; //城市搜索字段
Core.Search.initFilter(null,null);
</script>
{include file="/public/footer" /}